<?php
include( "inc/header.php" );
login_check( );

if ($_SESSION['acl'] != 1) admin_showerrs( "<li>你无权对短信帐户进行设置</li>", null, 0 ); //@author by chenhao 2010-01-19 禁止普通管理员设置短信帐户

if ($_GET['Action'] == 'set') {
	$posts = $_POST;
	foreach ($posts as $key => $value) {
		$posts[$key] = trim($value);
	}
	$user = $posts['user'];
	$password = $posts['pwd'];
	$id = $posts['id'];
	if (!empty($user) && !empty($password)) {
		$result = $db->query("SELECT * FROM tun2_sms WHERE id=$id");
		if ($db->num_rows($result)>0) { //表明已经有记录
			$sql = "UPDATE tun2_sms SET sms_user='{$user}',sms_password='{$password}' WHERE id=$id";
			$db->query($sql);
			addlog("修改短信帐号和密码", $_SESSION['user_name']);
			admin_showerrs('更新帐号成功啦',null,1);
		}else {
			$sql = "INSERT INTO tun2_sms (sms_user,sms_password) VALUES ('{$user}','{$password}')";
			$db->query($sql);
			addlog("设置新的短信帐号和密码", $_SESSION['user_name']);
			admin_showerrs('设置成功啦',null,1);
		}
	}else {
		admin_showerrs('短信帐户或帐户密码不能为空',null,0);
	}
}
$id = isset($_POST['id']) ? $_POST['id'] : 1;
$result = mysql_query("SELECT * FROM tun2_sms WHERE id=$id",$Conn);
$row = mysql_fetch_array($result);
?>
<table width="98%" border="1" align="center" cellpadding="5" cellspacing="0" class="table">
	<tr>
		<td>如果在设置中遇到什么问题或困难，请与<a href="http://www.22cn.cn" target="_blank">呜雷科技</a>联系</td>
	</tr>
</table>
<br>
<table width="98%" border="1" align="center" cellpadding="5" cellspacing="0" class="table">
<form id="form1" name="form1" method="post" action="Admin_Sms_Set.php?Action=set">
	<tr>
		<td align="right">短信帐户：</td>
		<td><label>
		    <input name="user" type="text" id="user" value="<?=$row['sms_user']?>" style="width:140px;" />
	      </label>
		</td>
	</tr>
	<tr>
		<td align="right">帐户密码：</td>
		<td><label>
		  <input name="pwd" type="password" id="pwd" value="<?=$row['sms_password']?>" style="width:140px;" />
		</label></td>
	</tr>
	<tr>
		<td>&nbsp;</td>
		<td><label>
		  <input name="id" type="hidden" id="id" value="<?=$row['id']?>" />
		  <input type="submit" name="Submit" value="确 认" />
		</label></td>
	</tr>
		 </form>
</table>